# 注意策略（先决定较好的策略再开始）
def chose(l):
    # 按正负数对列表进行分类
    l_1 = []
    l_2 = []
    l_3 = []
    for i in l:
        if i < 0:
            l_1.append(i)

        elif i == 0:
            l_2.append(i)

        else:
            l_3.append(i)

    return l_1, l_2, l_3

def low_number(l):
    # 分类讨论
    l_1, l_2, l_3 = chose(l)
    if len(l) == 3 or (len(l_1) == 1 and len(l_3) == 2):    # 一负一零一正或一负一零两正
        return 0

    if len(l_1) == 1 and len(l_3) > 2:      # 一负一零多正
        max_1 = 1
        for _ in range(0, 3):
            max_1 = max_1 * max(l_3)
            l_3.remove(max(l_3))
        return max_1

    if len(l_1) == 2 and len(l_3) == 1:     # 两负一零一正
        return l_1[0]*l_1[1]*l_3[0]

    if len(l_1) > 2 and (len(l_3) == 1 or len(l_3) == 2):      # 多负一零一正和多负一零两正
        l_1o2 = []
        for i in l_1:
            l_1o2.append(-i)

        max_2 = 1
        for _ in range(0, 2):
            max_2 = max_2*max(l_1o2)
            l_1o2.remove(max(l_1o2))
        return max(l_3)*max_2

    if len(l_1) > 2 and len(l_3) > 2:      # 多负一零多正
        l_1o3 = []
        for i in l_1:
            l_1o3.append(-i)

        max_3 = max(l_3)
        l_3.remove(max_3)

        max_a = max(l_1o3)
        l_1o3.remove(max_a)
        max_b = max(l_1o3)

        max_c = max(l_3)
        l_3.remove(max_c)
        max_d = max(l_3)

        if max_a * max_b > max_c * max_d:
            return max_a*max_b*max_3

        else:
            return max_c*max_d*max_3


l = [-1, -3, -4, -20, -33, -4, -20, -1, 0, 12, 33, 2, 13, 4, 5, 9, 3]
l.sort()
print(l)
print(low_number(l))


# 方法2
def func(l):
    l.sort()
    return max(l[0]*l[1]*l[-1], l[-1]*l[-2]*l[-3])

print(func(l))